'use strict';
const Controller = require('egg').Controller;

class CityController extends Controller {
  // 查询所有的城市信息
  async index() {
    try {
      const { ctx, service } = this;
      const citylInfo = await service.city.getCityList();
      if (citylInfo) {
        ctx.body = {
          code: 200,
          msg: 'ok',
          data: citylInfo,
        };
      } else {
        ctx.body = {
          code: 400,
          msg: '数据库信息获取失败',
        };
      }
    } catch (error) {
      return error;
    }
  }

  // 城市id查询其对应的所有酒店信息
  async show() {
    try {
      const { ctx, service } = this;
      const id = ctx.params.id;
      const resultInfo = await service.city.getListByCityid(id);
      // console.log(resultInfo);
      if (resultInfo) {
        ctx.body = {
          code: 200,
          msg: 'ok',
          data: resultInfo,
        };
      } else {
        ctx.body = {
          code: 500,
          msg: '数据库未找到你要查询的信息',
        };
      }
    } catch (error) {
      return error;
    }
  }
}
module.exports = CityController;
